import store from "../store"
import { userActionType } from "../store/modules/user"
import { cloneDeep, handleUrlParams } from "./index"
import { dictActionType } from "@/store/modules/dict"
import { getShowNginxPicUrl } from "@/utils/settings"

export default {
  //生成推荐官shareInfo
  async getTJGShareInfo(params = {}) {
    //带上推荐官id
    const userInfo = await store.dispatch(userActionType.action.userInfo)
    const id = userInfo.id
    //默认的分享图片
    if ([null, undefined].includes(params.imageUrl)) {
      params.imageUrl = getShowNginxPicUrl("age7xckyR1ykt9XVPgwP.jpg")
    }
    return {
      ...params,
      path: handleUrlParams(params.path, {
        shareType: "TJG",
        shareUserId: id,
      }),
      title: params.title || "我吹爆这个大学生刷题神器",
      imageUrl: params.imageUrl,
    }
  },
  // path 为分享的页面路径；title 为分享的标题；imageUrl 为分享的图片
  async getDefaultShareInfo(params = {}) {
    return await this.getTJGShareInfo({
      path: "/pages/index/index",
      ...params,
    })
  },
  // path 为分享的页面路径；title 为分享的标题；imageUrl 为分享的图片，获取没有带上分享参数的分享信息
  async getShareInfoWithoutShareParams(data = {}) {
    const params = cloneDeep(data)
    //默认的分享图片
    if ([null, undefined].includes(params.imageUrl)) {
      params.imageUrl = getShowNginxPicUrl("age7xckyR1ykt9XVPgwP.jpg")
    }
    //默认分享标题
    if ([null, undefined].includes(params.title)) {
      params.title = "我吹爆这个大学生刷题神器"
    }
    return params
  },
}
